package com.tomowork.commons;

public class ServerResponse<T> {
    private int code ;
    private String msg ;
    private T data ;
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T>  ServerResponse<T> success(){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.SUCCESS.getCode());
        return serverResponse ;
    }

    public static <T>  ServerResponse<T> success(String msg,T data){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.SUCCESS.getCode());
        serverResponse.setMsg(msg);
        serverResponse.setData(data);
        return serverResponse ;
    }
    public static <T>  ServerResponse<T> success(T data){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.SUCCESS.getCode());
        serverResponse.setData(data);
        return serverResponse ;
    }
    public static <T>  ServerResponse<T> success(String msg){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.SUCCESS.getCode());
        serverResponse.setMsg(msg);
        return serverResponse ;
    }
    public static <T> ServerResponse<T> fail(){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.ERROR.getCode());
        return serverResponse ;
    }
    public static <T> ServerResponse<T> fail(String msg,T data){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.ERROR.getCode());
        serverResponse.setMsg(msg);
        serverResponse.setData(data);
        return serverResponse ;
    }
    public static <T> ServerResponse<T> fail(String msg){
        ServerResponse<T> serverResponse = new ServerResponse<>() ;
        serverResponse.setCode(ResponseCode.ERROR.getCode());
        serverResponse.setMsg(msg);
        return serverResponse ;
    }
}
